#ifndef MAIN_H
#define MAIN_H

#include "LPC214x.h"
#include <stdint.h>
#include <stdlib.h>

//#define DEBUG	1		// used for printing to the serial terminal out of the programming pins

#define LOG_DATA            0     // set this to 1 to log data to the uSD card

//================================
//		Boolean Defines
//================================
#define ON	0
#define OFF	1
#define TRUE    1
#define FALSE   0

//================================
//			I/O Defines
//================================
#define P0DIR  FIO0DIR
#define P0SET  FIO0SET
#define P0CLR  FIO0CLR
#define P0PIN  FIO0PIN

#define P0PIN1 FIO0PIN1
#define P0PIN2 FIO0PIN2
#define P0PIN3 FIO0PIN3
#define P0PIN4 FIO0PIN4

#define P1DIR  FIO1DIR
#define P1SET  FIO1SET
#define P1CLR  FIO1CLR
#define P1PIN  FIO1PIN

#define P1PIN1 FIO1PIN1
#define P1PIN2 FIO1PIN2
#define P1PIN3 FIO1PIN3
#define P1PIN4 FIO1PIN4



#define ENABLE_INTERRUPTS   __asm__ volatile (                      \
                                          "mrs r3,cpsr;"        \
                                          "bic r3,r3,#0xC0;"    \
                                          "msr cpsr,r3"         \
                                          :                     \
                                          :                     \
                                          : "r3"                \
                                         )

#define DISABLE_INTERRUPTS  __asm__ volatile (                      \
                                          "mrs r0,cpsr;"        \
                                          "orr r1,r0,#0xC0;"    \
                                          "msr cpsr_c,r1;"      \
                                          :                     \
                                          :                     \
                                          : "r0", "r1"          \
                                         )


#define CHIP_SELECT	(1<<20)
#define SPI_SLAVE_CS    (1<<20)  //pin P0.20

#define LOW_COAST_PIN       (1<<1)    // pin P0.0  (TXO-0 on Logomatic v2)
#define HIGH_COAST_PIN      (1<<0)    // pin P0.1  (RXI-0 on logomatic v2)

#define MANUAL_PIN          (1<<10)   // pin P0.10 (pin p7 on logomatic v2)
#define AUTO_PIN            (1<<10)   // pin P0.12 (pin p8 on Logomatic v2)

#define SelectAccel()	P0CLR = CHIP_SELECT
#define UnselectAccel()	P0SET = CHIP_SELECT

//================================
//		PushTracker Defines
//================================
#define LOG_INTERVAL		30
#define ODO_INTERVAL		5
#define WRITE_INTERVAL		2000
#define SYNC_INTERVAL		WRITE_INTERVAL



static void delay_ms(uint32_t count)
{
   uint64_t countMs  = count * 8000;
   while (countMs--);
}

/*******************************************************************************
*                                                                              *
* TYPES                                                                        *
*                                                                              *
*******************************************************************************/

void loggingTaskHandler( void );

#endif